package com.idroid.widget;

import android.R.color;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

/**
 * @author oushuhua
 * @date 2015年8月20日
 */
public abstract class BasicPopup extends PopupWindow {
    public Context mContext;

    public BasicPopup(Context context) {
        this(context, ViewGroup.LayoutParams.MATCH_PARENT);
    }

    public BasicPopup(Context context, int height) {
        super(context);
        mContext = context;
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(height);
        setTouchable(true);
        setOutsideTouchable(true);
        setFocusable(true);
        ColorDrawable cd = new ColorDrawable(context.getResources().getColor(color.transparent));
        setBackgroundDrawable(cd);
        setContentView();
    }

    /**
     * 让popwindow不受软键盘弹出影响，始终保持在固定位置
     */
    public void setKeybroadHide(){
        this.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);//让popwindow不受软键盘弹出影响，始终保持在底部
        this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); //让popwindow不受软键盘弹出影响，始终保持在底部
    }

    public void setContentView() {
        setContentView(getView());
    }

    /**
     * 类似于Adapter.getView,返回的view自动添加为ContentView
     *
     * @return
     */
    public abstract View getView();

    public Context getContext() {
        return mContext;
    }

}
